<?php session_start();

    // get Session
    $id_temp = $_SESSION['id_content'];
    $userFromSession = $_SESSION['user_name'];

    // query sort comment by time
    $querySelectComment = "select id_comment,user_name, comment_text, Concat ( Floor(Hour(TIMEDIFF (comment_time, now()))/24), ' days ',
                                               MOD(HOUR(TIMEDIFF(comment_time, now())), 24), ' hours ',
                                               MINUTE (TIMEDIFF(comment_time, now())), ' minutes')as time from
    comment natural join user_comment where comment.id_content =$id_temp order by time";
    $resultGetComment = mysql_query($querySelectComment);

    // get next id_content for image naming
    global $curIDComment;
    $qCount = mysql_query("SELECT MAX(id_comment) FROM comment");
    $results = mysql_fetch_array($qCount);
    $curIDComment = $results['MAX(id_comment)'] + 1;

    echo "
    <div class='rect'>
        <div class='comment'>
            <form id='comment_form' name='comment_form' method='post' enctype='multipart/form-data'>
                <textarea id='comment_form_textarea' name='text_comment' cols='30' rows='5'></textarea>
                <input type='button' id='comment_form_submit' value='Comment' onclick='submit_comment(\"".$userFromSession."\",".$curIDComment.")'/>
            </form>
            <div id='commentList'>";

    //  ",\"".$_POST['text_comment']."\

    // id Content nanti diubah pake session dari user
    $queryGetTotalComment = "select count(id_comment) as totalComment  from comment where id_content=$id_temp";
    $resultTotalComment = mysql_query($queryGetTotalComment);
    while ($rowTotal = mysql_fetch_array($resultTotalComment)){
        echo "<h3 id=\"totalComment\">Total Comment : ".$rowTotal['totalComment']."</h3>";
    }

    while ($rowComment = mysql_fetch_array($resultGetComment)){
        echo '<div class="comment_list">';
        echo "<img src='images/avatar/like_button.jpg' width='50px' height='50px' style='float: left;'></img>";
        echo "<button type='button' onclick='deleteComment(\"".$userFromSession."\",".$rowComment['id_comment'].")' style='float: right;'>X</button>";
        echo '<h5>'.$rowComment['user_name'].'</h5><br/>';
        echo '<h5>'.$rowComment['time'].'</h5><br/>';
        echo '<h3>'.$rowComment['comment_text'].'</h3>';
        echo '</div>';
    }

    echo '      <script type="text/javascript" src="script/detail.js"></script>
            </div>
        </div>
    </div>';

?>